
$(function(){
	show_detail.run();

});

var show_detail = {	
		run: function(){
			this.__init__();
			this._start_();
			this._bind_events();
		},
		
		__init__: function(){
			this.contextPath = $("#contextPath").val() || "";
			this.showId = $("#showId").val();
			this.type = $("#type").val();		
			this.category = $("#category").val();
			this.itemUrl = $("#itemUrl").val();
			this.title = $("#title").val();
			this.source = $("#source").val();
			this.vdInstalled = vd.check();
		},
		
		_start_: function(){
			side_pub._init_side_genre_decade(this);
			share.run();		
		},
		
		_bind_events: function(){
			
			//play now btn
			$("#play_btn").click(function(){
				var title = show_detail.title;
				_gaq.push(['_trackEvent', 'music', 'Play', title]);
				if(show_detail.source == 'Vevo'){
					type = 'music';
				}
				var url = show_detail.contextPath + "/music/" + show_detail.category + "/watch-" + show_detail.showId;
				location.href = url;
				return false;
			});
			
			
			var locaIndex = location.href.indexOf("#"); 
			var localUrl = location.href;
			if(locaIndex > 0){
				localUrl = localUrl.substring(0,locaIndex);
			}
			$("#fb-comments").attr("data-href", localUrl);
			
			$("#genre_div > div > ul > li > a").click(function() {
				show_detail.genre = $(this).attr("genre");
				show_detail._genre_popular_relocation_event();
				return false;
			});

			$("#side_category_div > ul > li > a").click(function() {
				show_detail.popular = $(this).attr("popular");
				show_detail._genre_popular_relocation_event();
				return false;
			});
			
			$("#m_info_cont > ul > li > a.btn_play2").click(function(){
				var href = $(this).attr("href");
				var genre = show_detail.genre;
				var popular = show_detail.popular;
				var data = [];
				if(genre){
					data.push("genre=" + genre);
				}
				if(popular){
					data.push("period=" + popular);
				}
				_gaq.push(['_trackEvent', 'Music', 'Play', href]);
				location.href = href + "#" + data.join("&");
				return false;
			});
		},
		
		_genre_popular_relocation_event: function(){
			var genre = show_detail.genre;
			var popular = show_detail.popular;
			var params = [];
			if(genre){
				params.push("genre=" + genre);
			}
			if(popular){
				params.push("period=" + popular);
			}
			if(!genre && !popular){
				location.href = main.contextPath + "/music/video/";
				return false;
			}
			location.href = main.contextPath + "/music/videos#" + params.join("&");
		},
};

var share = {
		run: function(){
			$("#share_btn").click(function(){
				$("#share_fb_div").slideToggle();
				$("#share_fb_div > span.share-close").click(function(){
					$("#share_fb_div").slideUp();
				});
			});
			
			var url = location.href;
			$("#share_input").val(url);
			
			$("#fb_share_a").click(function(){
				var fbUrl = "https://www.facebook.com/sharer.php?u=" + encodeURIComponent(url);
				_gaq.push(['_trackEvent', 'Movie', 'fb_share', url]);	
				window.open(fbUrl);
			});
			
			$("#tw_share_a").click(function(){
				var twUrl = "https://twitter.com/share?url=" +encodeURIComponent(url);
				_gaq.push(['_trackEvent', 'Movie', 'twitter_share', url]);				
				window.open(twUrl);
			});
		}
	};
